home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 201-225 / 216 / backdrop / src / atoi.a next >
Text File  |  1995-03-13  |  669b  |  28 lines

  1. * :ts=8
  2. *
  3. * A very simple function which simply converts an ASCII string to its numeric
  4. * equivalent. It is MUCH smaller than it's equivalent in the Lattice
  5. * library.
  6. *
  7.  
  8.     xdef    atoi
  9.  
  10.     csect   text,0,0,1,2
  11.  
  12. atoi:
  13.     moveq    #0,d0            ; Initialise integer to 0
  14.     moveq    #0,d1            ; Initialise temporary variable
  15.     move.l    4(a7),a0        ; Get pointer to string
  16. loop:
  17.     move.b    (a0)+,d1        ; Get next character from string
  18.     subi.b    #$30,d1            ; Convert to range 0-9
  19.     cmpi.b    #10,d1            ; If outside range,
  20.     bhi.s    exit            ; then return to caller
  21.     mulu    #10,d0            ; Update count
  22.     add.l    d1,d0            ; Add in new digit
  23.     bra.s    loop            ; And go back for next digit
  24. exit:
  25.     rts                ; Return with number in D0
  26.  
  27.     end
  28.